<?php
/**
 * Created By virus_cms
 * Author: Virus
 * Date: 2020/3/2
 * Time: 13:55
 */

namespace app\admin\controller;


use app\BaseController;
use app\common\bussiness\AdminTableBussiness;
use think\App;

class AdminTable extends BaseController
{
    protected $adminTableBussiness = null;

    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->adminTableBussiness = new AdminTableBussiness();
    }

    public function getAllTable()
    {
        if (!$this->request->isPost()) {
            $this->error('非法请求类型');
        }
        $data = $this->adminTableBussiness->getAllTables();

        return writeJson(config('status.success'), "获取所有表", $data);
    }

    public function getAllTableFields()
    {
        $data = $this->adminTableBussiness->getAllTableFields(env('database.prefix').'admin');

        return writeJson(config('status.success'), "获取该表中的所有字段", $data);
    }

    public function codeGenerator()
    {
        if (!$this->request->isPost()) {
            $this->error('非法请求类型');
        }

        $tableName = $this->request->param('tableName', '', 'trim');

        if ($tableName == null) {
            return writeJson(config('status.error'), "表名不存在");
        }
    }
}